<?php
/* SVN FILE:: $Id: app_controller.php 4126 2010-10-18 08:33:48Z sparkwang $ */
/**
 * file comments here ...
 *
 * @package
 * @subpackage
 * @copyright 		Copyright (c) 2010 tencent
 * @author			sparkwang
 * @version			$LastChangedRevision: 4126 $
 * @modifiedby		$LastChangedBy: sparkwang $
 * @lastmodified	$LastChangedDate: 2010-10-18 16:33:48 +0800 (星期一, 2010-10-18) $
 */

/**
 * AppController
 *
 */
class AppController extends Controller {
	var $check_login = false;
	var $check_auth = true;
	var $auth_trim = ';';
    
	const INFO_TYPE_ERROR = 'error';
    const INFO_TYPE_SUCCESS = 'success';
	
	var $super_admin = array(		
		'ansrunwu','jackxzhou','shihaixiao'
	);
	function beforeFilter() {
		$this->init();
		$this->__check_login();
		return parent::beforeFilter();
	}
	function init()
	{
		return true;
	}
	function __check_login() 
	{
		//服务器导数据请求校验，服务器导数据请求不需要登录，校验规则，最后一个参数是api
		//site/get_report_data_main_dpt/1/1/1/1/api
		if (isset($_GET['url'])){
			$url = $_GET['url'];
			if (substr($url, -1) == '/'){
				$url = substr($url, 0, -1);
			}
			if (substr($url, -3) == 'api'){
				return true;
			}
		}
		//服务器导数据请求校验结束
		
		if (!$this->check_login || isset($_SESSION['user_id'])) 
		{
			return true;
		}
		else 
		{
			header("Location:/login/index"); 
			exit;
		}
	}
    protected function __show_info($layout, $message, $info_type = AppController::INFO_TYPE_ERROR, $return_url = NULL, $use_history_back = FALSE){

        $this->set('layout', $layout);
        $this->set('message', $message);
        $this->set('info_type', $info_type);
        $this->set('return_url', $return_url);
        $this->set('use_history_back', $use_history_back);
        
        $this->render(NULL, $layout, 'views/error/info.thtml');
        exit(0);
    }
}